home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / DUNESRC.ZIP / DUNESRC.PAS < prev    next >
Pascal/Delphi Source File  |  1996-07-03  |  4KB  |  162 lines

  1. {I downloaded the DUNE! BBStro from CDROM.COM incoming/code-section,
  2.  and wondered that there  was no source. Mmmmmhhhhh? Thanx to Niklas
  3.  Beisert/pascal (CubicTeam) for his help, he used this effect before
  4.  me in Lasse Reinbφng (and also Nooon in their great ASSEMBLY#1-demo
  5.  Stars). So if you intend to rip the code,  please greet me,  or one
  6.  of those groups mentioned before.  The source is not commented very
  7.  well, but: REAL CODERS DON'T NEED COMMENTS
  8.  
  9.  (C) 1995 by QuoVadis}
  10.  
  11. {$G+}{$M 5000,0,40000}
  12. const factor=7;
  13. type palette=array[0..767] of byte;
  14. var bseg,bseg2:word;
  15.     xarray:array[0..319] of word;
  16.     yarray:array[0..399] of word;
  17.     cosinus:array[0..255] of byte;
  18.     sinus:array[0..255] of byte;
  19.     pal:palette;
  20.     x,y:byte;
  21.     i:word;
  22.  
  23. {$l scale.obj}
  24. procedure ScaleUp(source,dest:word);External; { This is where the stuff goes }
  25. procedure Fire(dest:word);External;           { Standard blur }
  26. procedure CopyDW(source,dest:word);External;  { 32-bit copy }
  27. procedure Dot(x,y,where:word;c:byte);External;{ No circle :-( }
  28.  
  29. procedure Mode(md:word);assembler;
  30. asm
  31.   mov ax,md
  32.   int 10h
  33. end;
  34.  
  35. function KeyPressed:byte;assembler;
  36. {Mmmhh, faster ?}
  37. asm
  38.   in al,$60
  39.   xor ah,ah
  40. end;
  41.  
  42. procedure SetPal;assembler;
  43. asm
  44.   cli
  45.   mov si,offset pal
  46.   mov DX,3dah
  47.   @l1:
  48.   in AL,DX
  49.   test AL,8d
  50.   jnz @l1
  51.   @l2:
  52.   in AL,DX
  53.   test AL,8d
  54.   jz @l2
  55.   mov cx,768
  56.   mov dx,3C8h
  57.   xor al,al
  58.   out dx,al
  59.   inc dx
  60.   rep outsb
  61.   sti
  62. END;
  63.  
  64. procedure ramp(scol,r1,g1,b1,ecol,r2,g2,b2:byte;var p:palette);
  65. {ramp colors}
  66. var i:word;
  67.     r,g,b:real;
  68. begin
  69.   i:=scol;
  70.   r:=(r2-r1)/(ecol-scol);
  71.   g:=(g2-g1)/(ecol-scol);
  72.   b:=(b2-b1)/(ecol-scol);
  73.   repeat
  74.     p[i*3]  :=r1+round(r*(i-scol));
  75.     p[i*3+1]:=g1+round(g*(i-scol));
  76.     p[i*3+2]:=b1+round(b*(i-scol));
  77.     inc(i);
  78.   until i=ecol+1;
  79. end;
  80.  
  81. procedure SetUpBuffer(var segment:word;size:word);
  82. {I HATE GETMEM}
  83. var StartAdress:word;
  84. begin
  85.   asm
  86.     mov ax,4821h
  87.     mov bx,size
  88.     int 21h
  89.     mov dx,ax
  90.     jnb @l1
  91.       mov dx,0a000h
  92.       jmp @l2
  93.     @l1:
  94.       shl bx,2
  95.       mov cx,bx
  96.       mov es,ax
  97.       xor di,di
  98.       xor ax,ax
  99.       rep stosw
  100.     @l2:
  101.     mov StartAdress,dx
  102.   end;
  103.   segment:=StartAdress;
  104.   if StartAdress=$0a000 then begin
  105.     asm mov ax,3h;int 10h;end;
  106.     Writeln('Critical error - not enough memory to setup buffer');
  107.     halt;
  108.   end;
  109. end;
  110.  
  111. procedure FreeBuffer(segment:word);assembler;
  112. {I HATE FREEMEM, TOO}
  113. asm
  114.   mov ax,4921h
  115.   mov bx,segment
  116.   int 21h
  117. end;
  118.  
  119. procedure init;
  120. var i:word;
  121. begin
  122.   SetUpBuffer(bseg,4096);
  123.   SetUpBuffer(bseg2,4096);
  124.   {Just a few precalcs to gain speed}
  125.   for i:=0 to 255 do cosinus[i]:=round(cos(2*pi*i/255)*35+82);
  126.   for i:=0 to 255 do sinus[i]:=round(sin(2*pi*i/255)*80+140);
  127.   for i:=0 to 319 do xarray[i]:=round(i/319*(319-(2*factor)))+factor;
  128.   for i:=0 to 199 do begin
  129.                        yarray[2*i]:=  round(i/199*(199-(2*factor))+factor)*320;
  130.                        yarray[2*i+1]:=round(i/199*(199-(2*factor))+factor)*320;
  131.                      end;
  132.   ramp(  0, 0, 0, 0, 31,26, 3,38,pal);
  133.   ramp( 32,26, 3,38, 63,15,39,63,pal);
  134.   ramp( 64,15,39,63, 95,63,63,63,pal);
  135.   ramp( 96,63,63,63,111,63,63, 3,pal);
  136.   ramp(112,63,63, 3,130,63, 3,27,pal);
  137.   mode($13);setpal;
  138. end;
  139.  
  140. procedure leave;
  141. begin
  142.   FreeBuffer(bseg);
  143.   FreeBuffer(bseg2);
  144.   mode(3);
  145. end;
  146.  
  147. begin
  148.   init;
  149.   repeat
  150.     for i:=1 to 20 do dot(sinus[x]+random(30),cosinus[x]+random(30),bseg,130);
  151.     inc(x,4);
  152.     fire(bseg);
  153.     ScaleUp(bseg,bseg2);
  154.     CopyDW(bseg2,$0a000);
  155.     for i:=1 to 40 do dot(random(320),random(140)+15,bseg2,100);
  156.     fire(bseg2);
  157.     ScaleUp(bseg2,bseg);
  158.     CopyDW(bseg,$0a000);
  159.   until keypressed=1;
  160.   leave;
  161.   Writeln('Coded by QuoVadis in 1995');
  162. end.